package com.bnlr.lrparking.widget;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.bnlr.lrparking.model.StallListBean;

import java.util.List;

/**
 * 标签布局
 */

public class LabelLinearLayout extends LinearLayout{
    private Context context;
    public LabelLinearLayout(Context context) {
        this(context,null);
    }

    public LabelLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LabelLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setOrientation(HORIZONTAL);
    }
    public void setLabels (List<StallListBean.DataBean.DiscountBean> datas) {
        for (int i = 0; i < datas.size(); i++) {
            SuperTextView superTextView = new SuperTextView(context);
            superTextView.setText(datas.get(i).getTitle());
            superTextView.setTextSize(12);
            superTextView.setBackGround(Color.parseColor("#" + datas.get(i).getBackColor()));
            superTextView.setTextColor(Color.parseColor("#" + datas.get(i).getTextColor()));
            superTextView.setSingleLine();
            superTextView.setEnables(false);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 0, 2, 0);
            superTextView.setLayoutParams(lp);
            superTextView.setEllipsize(TextUtils.TruncateAt.END);
            addView(superTextView);
        }

    }
}
